﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;
using DuLieu;

namespace GiaoDien
{
    public partial class Form1 : Form
    {
        DichVuDAO dvDAO = new DichVuDAO();
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<DichVuDTO> list = dvDAO.GetListDichVu();
            if (list == null)
            {
                MessageBox.Show("List is NULL");
                return;
            }
            for (int i=0; i < list.Count; i++)
            {
                MessageBox.Show("Name: " + list[i].TenDichVu + ", ID: " + list[i].MaDichVu);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DichVuDTO dv = dvDAO.GetDichVuByID(1);
            if(dv != null)
                MessageBox.Show("Name: " + dv.TenDichVu + ", ID: " + dv.MaDichVu);
            else
                MessageBox.Show("Not found");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DichVuDTO dv = dvDAO.GetDichVuByName("ATM");
            if(dv != null)
            MessageBox.Show("Name: " + dv.TenDichVu + ", ID: " + dv.MaDichVu);
            else
                MessageBox.Show("Not found");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            DichVuDTO dv = new DichVuDTO();
            dv.MaDichVu = 1000;
            dv.TenDichVu = "TEMP";

            try
            {
                if (dvDAO.InsertDichVu(dv))
                {
                    MessageBox.Show("Insert Successed");
                }
                else
                {
                    MessageBox.Show("This service's ID is already.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            DichVuDTO dv = new DichVuDTO();
            dv.MaDichVu = 1000;
            dv.TenDichVu = "TEMP_UPDATE";

            try
            {
                if (dvDAO.InsertDichVu(dv))
                {
                    MessageBox.Show("Update Successed");
                }
                else
                {
                    MessageBox.Show("Not found service to update");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            try
            {
                if (dvDAO.DeleteDichVuByID(1000))
                {
                    MessageBox.Show("Delete Successed");
                }
                else
                {
                    MessageBox.Show("Not found service to delete");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                if (dvDAO.DeleteDichVuByName("TEMP"))
                {
                    MessageBox.Show("Delete Successed");
                }
                else
                {
                    MessageBox.Show("Not found service to delete");
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
